
package scm.inventoryControl.managedbean;

import commonInfrastructure.accountManagement.entity.WarehousePersonnelEntity;
import commonInfrastructure.accountManagement.session.WarehousePersonnelSessionBean;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import javax.servlet.http.HttpServletRequest;
import scm.inventoryControl.entity.ProductInventoryLevelEntity;
import scm.inventoryControl.session.stateless.InventoryControlSessionBean;


@ManagedBean
@ViewScoped
public class EditFinalGoodInventoryLevelManagedBean {
    @EJB 
    private InventoryControlSessionBean inventoryControl;
    private List<ProductInventoryLevelEntity>  inventoryList;
    
    public EditFinalGoodInventoryLevelManagedBean() {
    }
    
    public void edit(ActionEvent e){
        for(int i=0;i<inventoryList.size();i++){
            getInventoryControl().saveEdit(inventoryList.get(i));
        }
           FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Inventory level has been updated Successfully.", ""));
    }
    
    
    public void iniView(PhaseEvent event) {

        if (getInventoryList() == null) {
            setInventoryList((List<ProductInventoryLevelEntity>) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("thisInventory"));
        }
     
    }

    public List<ProductInventoryLevelEntity> getInventoryList() {
        return inventoryList;
    }

    public void setInventoryList(List<ProductInventoryLevelEntity> inventoryList) {
        this.inventoryList = inventoryList;
    }

    /**
     * @return the inventoryControl
     */
    public InventoryControlSessionBean getInventoryControl() {
        return inventoryControl;
    }

    /**
     * @param inventoryControl the inventoryControl to set
     */
    public void setInventoryControl(InventoryControlSessionBean inventoryControl) {
        this.inventoryControl = inventoryControl;
    }
    
}
